import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:get/get.dart';
import 'package:gw_github_flutter/common/route_name.dart';
import 'package:gw_github_flutter/tools/gwEasyRefrashManager.dart';
import 'package:gw_github_flutter/tools/gwGetManager.dart';

class SliverRouteNoAppBar extends StatefulWidget {
  SliverRouteNoAppBar({Key? key}) : super(key: key);

  @override
  State<SliverRouteNoAppBar> createState() => _SliverRouteNoAppBarState();
}

class _SliverRouteNoAppBarState extends State<SliverRouteNoAppBar> {
  var _itemCount = 10;
  @override
  Widget build(BuildContext context) {
    return Scaffold(
        body: EasyRefresh.builder(
            header: GwEasyRefrashManager.setRefrashHeader(
                clamping: true, mainAxisAlignment: MainAxisAlignment.end),
            onLoad: () async {
              await Future.delayed(Duration(seconds: 2), () {
                if (mounted) {
                  setState(() {
                    _itemCount += 10;
                  });
                }
              });
            },
            onRefresh: () async {
              await Future.delayed(Duration(seconds: 2), () {
                if (mounted) {
                  setState(() {
                    _itemCount = 10;
                  });
                }
              });
            },
            childBuilder: (context, physics) {
              return CustomScrollView(
                physics: physics,
                slivers: <Widget>[
                  const HeaderLocator.sliver(clearExtent: false),
                  SliverAppBar(
                      leading: IconButton(
                          icon: const Icon(Icons.arrow_back),
                          onPressed: () => GwGetRouteManager.pop()),
                      title: const Text(RouteName.sliverRoute_noAppBar),
                      actions: <Widget>[
                        IconButton(
                          icon: Icon(Icons.add),
                          onPressed: () {
                            print("添加");
                          },
                        ),
                        IconButton(
                          icon: Icon(Icons.more_horiz),
                          onPressed: () {
                            print("更多");
                          },
                        ),
                      ],
                      expandedHeight: 230.0,
                      floating: false,
                      pinned: true,
                      snap: false,
                      systemOverlayStyle: SystemUiOverlayStyle.dark,
                      // brightness: Brightness.dark,
                      flexibleSpace: GestureDetector(
                        onTap: () => GwGetRouteManager.pop(),
                        child: FlexibleSpaceBar(
                          background: Image.asset("imgs/fengjing.png",
                              fit: BoxFit.fitHeight),
                        ),
                      )),
                  SliverFixedExtentList(
                    itemExtent: 50.0,
                    delegate: SliverChildBuilderDelegate(
                      (context, index) => ListTile(
                        title: Text("Item $index"),
                      ),
                      childCount: _itemCount,
                    ),
                  ),
                  // const FooterLocator.sliver(clearExtent: true,),
                ],
              );
            }));
  }
}
